from .handle import handle

landList = {
        "land_id": 0,
        "land_title": "1号大棚",  # 标题
        "land_rules": "需要等待种植的种类成熟后方可寄出。", # 种植规则
        "imagesSlider": [
            "./resizeimg/6.jpg",
            "./resizeimg/7.jpg",
            "./resizeimg/8.jpg",
        ], # 轮播图
        "defaultImgIndex": 0, # 默认图片索引（取轮播图）
        "land_stock": 27,  # 土地总块数
        "land_planted": 3,  # 土地已种植数
        "items": "",
        "imageContent": ["./resizeimg/3.jpg",
                         "./resizeimg/1.jpg",
                         "./resizeimg/2.jpg",],  # 合种租地图片详情
        "vedios": "",  # 存放视频地址
        "status": 0,  # 状态
}

plantList = {
                "land_id": 2,
                "item_id": 0,
                "item_title": "白菜",
                "item_cycle": 50,
                "status": 0,
                "remark": "",
                "item_img": "./resizeimg/8.jpg",
                "item_price": 8.9,
                "item_count": 60,
                "item_weight": 5,
                "item_introduce": "空心菜是碱性食物，并含有钾、氯等调节水液平衡的元素，食后可降低肠道的酸度，预"
                                  "防肠道内的菌群失调，对防癌有益。所含的烟酸、维生素C等能降低胆固醇、甘油三酯，具有降脂减肥的功效。空心菜中的叶绿素有“绿色精灵”之称，可洁齿防龋除口臭，健美皮肤。",
}

class LeaseLandHandle(handle):
    def __init__(self):
        super(LeaseLandHandle, self).__init__()

    def updateLand(self, data):
        sliderimg_paths = data["imagesSlider"]
        contentimg_paths = data["imageContent"]
        temp = sliderimg_paths + contentimg_paths
        files = self._getFile(temp)
        print(files)

        del data["imagesSlider"]
        del data["imageContent"]
        data["sliderCount"] = sliderimg_paths.__len__()
        data["contentCount"] = contentimg_paths.__len__()
        url = self._base_url + "land_upload"

        return self._handle(url=url, data=data, files=files)

    def updatePlant(self, data):
        img_path = data["item_img"]
        files = {'file': open(img_path, "rb")}
        del data["item_img"]
        url = self._base_url + "plant_upload"

        return self._handle(url=url, data=data, files=files)

    # {"land_id": 1, "item_id": 1}
    def del_plant(self, land_id, item_id):
        data = {"land_id": land_id, "item_id": item_id}
        url = self._base_url + "del_plant"

        return self._handle(url=url, data=data)

    def del_land(self, land_id):
        data = {"land_id": land_id}

        url = self._base_url + "del_land"

        return self._handle(url=url, data=data)

    def land_sold_out(self, land_id):
        data = {"land_id": land_id}

        url = self._base_url + "land_sold_out"

        return self._handle(url=url, data=data)

    def land_show(self):
        url = self._base_url + "land_show"

        return self._handle(url=url, htype="GET")

def main():
    leaseLandHandle = LeaseLandHandle()
    #res = leaseLandHandle.updateLand(landList)
    #res = leaseLandHandle.updatePlant(plantList)
    #res = leaseLandHandle.del_plant(3, 1)
    res = leaseLandHandle.del_land(9)
    #res = leaseLandHandle.land_sold_out(1)
    #res = leaseLandHandle.land_show()
    #print(res["landList"].__len__())
    print(res)

if __name__ == '__main__':
    main()
